package com.example.black.myapplication.myhandler;

import android.util.Log;

import java.util.UUID;

public class MyActivityThread {

   public static void main(String[] args){
        MyLooper.perpareMainLooper();
        MyHandler myHandler = new MyHandler(){
            @Override
            protected void handleMessage(MyMessage myMessage) {
                super.handleMessage(myMessage);
                System.out.println("handleMessage: "+Thread.currentThread().getName()+" uuid "+myMessage.obj.toString());

            }
        };
        for (int i = 0;i<5;i++){
            new Thread(){
                @Override
                public void run() {
                    super.run();
                    while (true){
                        MyMessage myMessage = MyMessage.obtain();
                        myMessage.obj = UUID.randomUUID();
                        myHandler.sendMessage(myMessage);
                        System.out.println( "sendMessage: "+Thread.currentThread().getName()+" uuid "+myMessage.obj.toString() );

                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
        }
        MyLooper.loop();
        throw new RuntimeException("main thread is exit");
   }
}
